package com.hxc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;

@Controller
@RequestMapping("upload")
public class UploadController {

    @RequestMapping("/add.html")
    public String fileUpload3(@RequestParam("file") CommonsMultipartFile[] files) {
        try {
            //批量上传时遍历文件数组
            for (CommonsMultipartFile f : files) {
                System.out.println("fileName：" + f.getOriginalFilename());
                String path = "E:/upload/" + f.getOriginalFilename();
                File newFile = new File(path);
                f.transferTo(newFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/file.jsp";
    }

}
